/*
 *  Copyright 2008-2010 the original author or authors.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package org.openaecfm.spf.model;

/**
 * The simple entity instance.
 * @author Qiu Kuining
 */
public class SimpleEntityInstance extends EntityInstance {

    /**
     * Get the nodetype of SimpleEntityInstance.
     * @return
     */
    @Override
    public final NodeType getNodeType() {
        return NodeType.SIMPLE_ENTITY_INSTANCE;
    }

    private SimpleRecord simple_record;

    /**
     * Get the simple record.
     * @return
     */
    public SimpleRecord getSimpleRecord(){
        return simple_record;
    }

    /**
     * Set the simple record.
     * @param sr
     */
    public void setSimpleRecord(SimpleRecord sr) {
        this.simple_record = sr;
    }

    public SimpleEntityInstance() {
        super();
    }

    public SimpleEntityInstance(String keyword, String name) {
        super(name);
        simple_record = new SimpleRecord(keyword);
    }

    /**
     * Add a parameter.
     * @param p
     */
    public void addParameter(Parameter p) {
        simple_record.addParameter(p);
    }

    /**
     * Get the parameter by index i.
     * @param i
     * @return
     */
    public Parameter getParameter(int i) {
        return (Parameter) simple_record.getParameter(i);
    }

    /**
     * To string.
     * @return
     */
    @Override
    public String toString() {
        java.lang.StringBuffer b = new java.lang.StringBuffer();
        b.append(getName()).append("=").append(simple_record).append(";\n");
        return b.toString();
    }

    /**
     * Add a child node.
     * @param n
     */
    @Override
    public void addChild(Node n) {
        if (n instanceof SimpleRecord) {
            simple_record = (SimpleRecord) n;
        }else{
            simple_record.addChild(n);
        }
    }
}
